using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CompanyDomain;
using ShivamEMR.Model.DataInterfaces.CRMDataInterf;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model;
using ShivamEMR.Web.Models;
//using ShivamEMR.Web.Areas.Company.Models;

namespace ShivamEMR.Web.Areas.Company.Controllers
{   
    public class EmployeeScheduleController : Controller
    {
		private readonly IVenueRepository venueRepository;
		private readonly IScheduleRepository scheduleRepository;
		private readonly IEmployeeScheduleRepository employeescheduleRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public EmployeeScheduleController()
        {
            //venueRepository=Registry.RepositoryFactory.getven
            scheduleRepository = Registry.RepositoryFactory.GetScheduleRepository();
            employeescheduleRepository = Registry.RepositoryFactory.GetEmployeeScheduleRepository();
        }

        public EmployeeScheduleController(IVenueRepository venueRepository, IScheduleRepository scheduleRepository, IEmployeeScheduleRepository employeescheduleRepository)
        {
			this.venueRepository = venueRepository;
			this.scheduleRepository = scheduleRepository;
			this.employeescheduleRepository = employeescheduleRepository;
        }

        //
        // GET: /EmployeeSchedule/
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Index()
        {
            //return View(employeescheduleRepository.AllIncluding(employeeschedule => employeeschedule.Venue, employeeschedule => employeeschedule.Schedule));
            return View(employeescheduleRepository.All);
        }

        //
        // GET: /EmployeeSchedule/Details/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Details(Guid id)
        {
            return View(employeescheduleRepository.Find(id));
        }

        //
        // GET: /EmployeeSchedule/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Create()
        {
			ViewBag.PossibleVenues = venueRepository.All;
			ViewBag.PossibleSchedules = scheduleRepository.All;
            return View();
        } 

        //
        // POST: /EmployeeSchedule/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Create(EmployeeSchedule employeeschedule)
        {
            if (ModelState.IsValid) {
                employeescheduleRepository.Create(employeeschedule);
                employeescheduleRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleVenues = venueRepository.All;
				ViewBag.PossibleSchedules = scheduleRepository.All;
				return View();
			}
        }
        
        //
        // GET: /EmployeeSchedule/Edit/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Edit(Guid id)
        {
			ViewBag.PossibleVenues = venueRepository.All;
			ViewBag.PossibleSchedules = scheduleRepository.All;
             return View(employeescheduleRepository.Find(id));
        }

        //
        // POST: /EmployeeSchedule/Edit/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Edit(EmployeeSchedule employeeschedule)
        {
            if (ModelState.IsValid) {
                employeescheduleRepository.Update(employeeschedule);
                employeescheduleRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleVenues = venueRepository.All;
				ViewBag.PossibleSchedules = scheduleRepository.All;
				return View();
			}
        }

        //
        // GET: /EmployeeSchedule/Delete/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Delete(Guid id)
        {
            return View(employeescheduleRepository.Find(id));
        }

        //
        // POST: /EmployeeSchedule/Delete/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(Guid id)
        {
            var empsche = employeescheduleRepository.Find(id);
            employeescheduleRepository.Delete(empsche);
            employeescheduleRepository.Save();
            return RedirectToAction("Index");
        }
    }
}

